<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>手机商城</title>
   <link rel="stylesheet" href="../css/03.css">
</head>
<body>
<header>

    </div>
    <nav>
        <a href="#"><img src="../image/logo.png"></a>
        <ul>
            <li><a href="#">首页</a></li>
            <li><a href="#">产品</a></li>
            <li><a href="#">MIUI</a></li>
            <li><a href="#">云服务</a></li>
            <li><a href="#">资质证照</a></li>
            <li><a href="#">智能生活</a></li>
            <li><a href="#">下载app</a></li>
            <li><a href="#">联系我们</a></li>
        </ul>
        <button type="submit" onclick="cart()"
                style=" border: 2px solid #0099cc;border-radius: 5px;">
            购物车
        </button>
        <span style="color: deepskyblue" >${SESSION_USERNAME},欢迎！</span>
       <button type="submit" onclick="logout()"
               style=" border: 2px solid #d12f2f;border-radius: 5px;">
           退出登录
       </button>
        <c:set var="show" value="${SESSION_USERLEVEL}"/>
        <c:if test="${show eq true}">
            <button type="submit" onclick="tianjia()"
                    style=" border: 2px solid #d12f2f;border-radius: 5px;" >
                添加商品
            </button>
        </c:if>
    </nav>
</header>

<c:forEach items="${list}" var="li">
<div class="product">
    <img src="${li.image}" alt="Product Image" onclick="getDetail('${li.id}')">
    <h2>${li.itemName}</h2>
    <p>${li.description}</p>
    <p>${li.price}</p>
    <button onclick="add('${li.id}')">加入购物车</button>

    <c:set var="show" value="${SESSION_USERLEVEL}"/>
   <%--
        存在外键约束
   <c:if test="${show eq true}">
        <button type="submit" onclick="shanchu('${li.id}')"
                style=" border: 2px solid #d12f2f;border-radius: 5px;" >
            删除
        </button>
    </c:if>
    --%>
</div>
</c:forEach>


<img class="but" src="../image/button.png">
</body>

<script>
    function logout(){
        window.location.href="${pageContext.request.contextPath}/user/logout"
    }
    function cart(){
        window.location.href="${pageContext.request.contextPath}/shopCart/findCart"
    }
    function add(id){
        window.location.href="${pageContext.request.contextPath}/shopCart/addOne?iid="+id;
    }
    function getDetail(iid){
        window.location.href="${pageContext.request.contextPath}/item/getDetail?iid="+iid;
    }
    function tianjia(){
        window.location.href="${pageContext.request.contextPath}/pages/tianjia.jsp";
    }
    function shanchu(iid){
        window.location.href="${pageContext.request.contextPath}/item/delete?iid="+iid;
    }
</script>

</html>